const express = require('express')
const actsRouter = express.Router()
const fs = require('fs')

actsRouter.get('/actsData', (req, res) => {
    let actsData = require('../data/actsData.json') 
    res.send({ status: 0, message: '获取数据成功', data: actsData })
})
actsRouter.post('/actsadd',(req,res)=>{
    let actsData =require('../data/actsData.json') 
    actsData.push(req.body)
   fs.writeFile('./data/actsData.json', JSON.stringify(actsData),(error,data)=>{
    res.send({ status: 0, message: '添加成功' })
    })
   
})
actsRouter.post('/actsdel', (req,res)=>{
    let actsData =require('../data/actsData.json') 
        let index =  actsData.findIndex((item)=>req.body.id==item.id)
        actsData.splice(index,1)
        console.log(actsData);
     fs.writeFile('./data/actsData.json', JSON.stringify(actsData),(error,data)=>{
        res.send({ status: 0, message: '删除成功'})
    })
    
})
module.exports = actsRouter